# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=grantlee
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.2.0
pkgrel=1
pkgdesc="A string template engine based on the Django template system and written in Qt5 (mingw-w64)"
arch=('any')
url='http://www.grantlee.org/'
license=('LGPL2.1')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-graphviz")
options=('strip' 'staticlibs')
source=("http://downloads.grantlee.org/grantlee-${pkgver}.tar.gz"{,.asc})
sha256sums=('d6cd04de39a073a787c9ab8e72a0888e40779d21b83fbc788a1b36d31ac659d5'
            'SKIP')
validpgpkeys=(FCA530E51EE4331C2DF16637D264C7B1D02D6509) # Stephen Kelly <steveire@gmail.com>

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
#  apply_patch_with_msg 0001-A-really-important-fix.patch \
#    0002-A-less-important-fix.patch
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DBUILD_{SHARED,STATIC}_LIBS=ON \
      -DBUILD_TESTS=OFF \
      ../${_realname}-${pkgver}

  make
  make docs
}

#check() {
#  cd "${srcdir}"/build-${CARCH}
#  make check
#}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/
  install -Dm066 apidox/* ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/

#  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
